//
//  UserBSGetBarcodeDatail.m
//  
//
//  Created by 李飞 on 15/11/16.
//
//

#import "UserBSGetBarcodeDatail.h"
#import "ApplicationContext.h"
#import "ApiConfig.h"

@implementation UserBSGetBarcodeDatail

- (id)onExecute {
    
    
    NSDictionary *params = @{@"token":[ApplicationContext instance].token,@"page":_page,@"versionCode":kVersionCode,@"systemType":kSystemType};
    
    id result = [self remoteJSON:@"POST" url:[ApiConfig urlApiGetBarcodeDetail] params:params];
    UserBSGetBarcodeDatailResult *serviceResult = [[UserBSGetBarcodeDatailResult alloc] init];
    
    NSNumber *returnState = result[@"error"];
        
    NSMutableArray *detailArray = [NSMutableArray array];
    
    NSLog(@"!!!!!error%@",returnState);
    //成功时进行注册
    if ([returnState isEqualToNumber:@0])
    {
        
        serviceResult.isSucess = YES;
        
        id info = result[@"data"][@"info"];
        serviceResult.allpay = result[@"data"][@"all_pay"];
        serviceResult.monthpay = result[@"data"][@"theMonth_pay"];
        NSLog(@"!!!!!all_pay%@",serviceResult.allpay);
        NSLog(@"!!!!!theMonth_pay%@",serviceResult.monthpay);
        
        //解析数据库数据
        serviceResult.pageSize = (int) result[@"pageSize"];
//        if (![info isEqual:[NSNull null]]) {
            serviceResult.isLast = NO;
            [info enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
                NSDictionary *detail = @{@"time" : obj[@"time"], @"ticket_name" : obj[@"ticket_name"], @"student_name" : obj[@"student_name"]};
                
                [detailArray addObject:detail];
                NSLog(@"time%@     ticket_name%@       student_name%@",obj[@"time"],obj[@"ticket_name"],obj[@"student_name"]);
            }];
//        }
//        else
//        {
//            serviceResult.isLast = YES;
//        }

    }
    else
    {
        serviceResult.isSucess = NO;
        serviceResult.message = result[@"msg"];
    }
    

    serviceResult.data = detailArray;
    
    return serviceResult;
}
@end


@implementation UserBSGetBarcodeDatailResult
{}


@end
